lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

Regular Expressions (Python).sublime-syntax (3698B)


      1 %YAML 1.2
      2 ---
      3 name: Regular Expressions (Python)
      4 comment: Matches Python's regular expression syntax.
      5 scope: source.regexp.python
      6 hidden: true
      7 contexts:
      8   main:
      9     - match: (#)[^]\[(){}^$+*?\\|"']*$
     10       comment:
     11         We are restrictive in what we allow to go after the comment character to avoid
     12         false positives, since the availability of comments depend on regexp flags.
     13       scope: comment.line.number-sign.regexp
     14       captures:
     15         1: punctuation.definition.comment.regexp
     16     - match: '\\[bBAZzG]|\^|\$'
     17       scope: keyword.control.anchor.regexp
     18     - match: '\\[1-9][0-9]?'
     19       scope: keyword.other.back-reference.regexp
     20     - match: '[?+*][?+]?|\{(\d+,\d+|\d+,|,\d+|\d+)\}\??'
     21       scope: keyword.operator.quantifier.regexp
     22     - match: \|
     23       scope: keyword.operator.or.regexp
     24     - match: '\(\?\#'
     25       scope: punctuation.definition.comment.begin.regexp
     26       push:
     27         - meta_scope: comment.block.regexp
     28         - match: \)
     29           scope: punctuation.definition.comment.end.regexp
     30           pop: true
     31     - match: '\(\?[iLmsux]+\)'
     32       scope: keyword.other.option-toggle.regexp
     33     - match: '(\()(\?P=([a-zA-Z_][a-zA-Z_0-9]*\w*))(\))'
     34       scope: keyword.other.back-reference.named.regexp
     35     - match: (\()((\?=)|(\?!)|(\?<=)|(\?<!))
     36       captures:
     37         1: punctuation.definition.group.begin.regexp
     38         2: constant.other.assertion.regexp
     39         3: meta.assertion.look-ahead.regexp
     40         4: meta.assertion.negative-look-ahead.regexp
     41         5: meta.assertion.look-behind.regexp
     42         6: meta.assertion.negative-look-behind.regexp
     43       push:
     44         - meta_scope: meta.group.assertion.regexp
     45         - match: \)
     46           scope: punctuation.definition.group.end.regexp
     47           pop: true
     48         - include: main
     49     - match: '(\()(\?\(([1-9][0-9]?|[a-zA-Z_][a-zA-Z_0-9]*)\))'
     50       comment:
     51         We can make this more sophisticated to match the | character that separates
     52         yes-pattern from no-pattern, but it's not really necessary.
     53       captures:
     54         1: punctuation.definition.group.begin.regexp
     55         2: punctuation.definition.group.assertion.conditional.regexp
     56         3: variable.other.back-reference.regexp
     57       push:
     58         - meta_scope: meta.group.assertion.conditional.regexp
     59         - match: \)
     60           scope: punctuation.definition.group.end.regexp
     61           pop: true
     62         - include: main
     63     - match: '(\()((\?P<)([a-z]\w*)(>)|(\?:))?'
     64       captures:
     65         1: punctuation.definition.group.begin.regexp
     66         3: punctuation.definition.group.capture.regexp
     67         4: entity.name.other.group.regexp
     68         5: punctuation.definition.group.capture.regexp
     69         6: punctuation.definition.group.no-capture.regexp
     70       push:
     71         - meta_scope: meta.group.regexp
     72         - match: \)
     73           scope: punctuation.definition.group.end.regexp
     74           pop: true
     75         - include: main
     76     - include: character-class
     77   character-class:
     78     - match: '\\[wWsSdDhH]|\.'
     79       scope: constant.character.character-class.regexp
     80     - match: \\.
     81       scope: constant.character.escape.backslash.regexp
     82     - match: '(\[)(\^)?'
     83       captures:
     84         1: punctuation.definition.character-class.begin.regexp
     85         2: keyword.operator.negation.regexp
     86       push:
     87         - meta_scope: constant.other.character-class.set.regexp
     88         - match: \]
     89           scope: punctuation.definition.character-class.end.regexp
     90           pop: true
     91         - include: character-class
     92         - match: '((\\.)|.)\-((\\.)|[^\]])'
     93           scope: constant.other.character-class.range.regexp
     94           captures:
     95             2: constant.character.escape.backslash.regexp
     96             4: constant.character.escape.backslash.regexp